import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDEquipment {
	/**装备id*/
	id,
	/**品质*/
	color,
	/**装备部位*/
	group,
	/**主属性词条，随机一条*/
	primeAttribute,
	/**主属性随机id*/
	primeRMath,
	/**副属性条数*/
	randomNum,
	/**副属性词条*/
	randomAttribute,
	/**副属性随机id*/
	randomRMath,
	/**固定属性*/
	baseMath,
	/**被动技能*/
	skill,
	/**套装id*/
	suit,
	/**符文id*/
	runeID,
	/**符文萃取消耗道具*/
	extractCostItem,
	/**符文萃取消耗数量*/
	extractCosNum,
	/**样式*/
	style,
	/**装备类型*/
	type,
	/**未生成时显示属性1攻击2生命3防御*/
	showAttributeType,
	/**未生成时显示属性1攻击2生命3防御*/
	showAttributeNum,

	/**枚举数量*/
	EnumCount
}



export class CDEquipment{
	/**装备id*/
	public id: number;
	/**品质*/
	public color: number;
	/**装备部位*/
	public group: number;
	/**主属性词条，随机一条*/
	public primeAttribute: number[];
	/**主属性随机id*/
	public primeRMath: number;
	/**副属性条数*/
	public randomNum: number[];
	/**副属性词条*/
	public randomAttribute: number[];
	/**副属性随机id*/
	public randomRMath: number;
	/**固定属性*/
	public baseMath: number;
	/**被动技能*/
	public skill: number;
	/**套装id*/
	public suit: number;
	/**符文id*/
	public runeID: number;
	/**符文萃取消耗道具*/
	public extractCostItem: number;
	/**符文萃取消耗数量*/
	public extractCosNum: number;
	/**样式*/
	public style: number;
	/**装备类型*/
	public type: number;
	/**未生成时显示属性1攻击2生命3防御*/
	public showAttributeType: number;
	/**未生成时显示属性1攻击2生命3防御*/
	public showAttributeNum: number[];


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDEquipment.id: return this.id;
			case E_CDEquipment.color: return this.color;
			case E_CDEquipment.group: return this.group;
			case E_CDEquipment.primeAttribute: return this.primeAttribute;
			case E_CDEquipment.primeRMath: return this.primeRMath;
			case E_CDEquipment.randomNum: return this.randomNum;
			case E_CDEquipment.randomAttribute: return this.randomAttribute;
			case E_CDEquipment.randomRMath: return this.randomRMath;
			case E_CDEquipment.baseMath: return this.baseMath;
			case E_CDEquipment.skill: return this.skill;
			case E_CDEquipment.suit: return this.suit;
			case E_CDEquipment.runeID: return this.runeID;
			case E_CDEquipment.extractCostItem: return this.extractCostItem;
			case E_CDEquipment.extractCosNum: return this.extractCosNum;
			case E_CDEquipment.style: return this.style;
			case E_CDEquipment.type: return this.type;
			case E_CDEquipment.showAttributeType: return this.showAttributeType;
			case E_CDEquipment.showAttributeNum: return this.showAttributeNum;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDEquipment.id: this.id = v; break;
			case E_CDEquipment.color: this.color = v; break;
			case E_CDEquipment.group: this.group = v; break;
			case E_CDEquipment.primeAttribute: this.primeAttribute = v; break;
			case E_CDEquipment.primeRMath: this.primeRMath = v; break;
			case E_CDEquipment.randomNum: this.randomNum = v; break;
			case E_CDEquipment.randomAttribute: this.randomAttribute = v; break;
			case E_CDEquipment.randomRMath: this.randomRMath = v; break;
			case E_CDEquipment.baseMath: this.baseMath = v; break;
			case E_CDEquipment.skill: this.skill = v; break;
			case E_CDEquipment.suit: this.suit = v; break;
			case E_CDEquipment.runeID: this.runeID = v; break;
			case E_CDEquipment.extractCostItem: this.extractCostItem = v; break;
			case E_CDEquipment.extractCosNum: this.extractCosNum = v; break;
			case E_CDEquipment.style: this.style = v; break;
			case E_CDEquipment.type: this.type = v; break;
			case E_CDEquipment.showAttributeType: this.showAttributeType = v; break;
			case E_CDEquipment.showAttributeNum: this.showAttributeNum = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDEquipment> = new HashMap<number, CDEquipment>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDEquipment[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDEquipment();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].color = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].group = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].primeAttribute = [];
			const attrArray = list[i].primeAttribute;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].primeRMath = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].randomNum = [];
			const attrArray = list[i].randomNum;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].randomAttribute = [];
			const attrArray = list[i].randomAttribute;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].randomRMath = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].baseMath = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].skill = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].suit = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].runeID = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].extractCostItem = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].extractCosNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].style = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].type = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].showAttributeType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].showAttributeNum = [];
			const attrArray = list[i].showAttributeNum;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDEquipment{
		return this.datas ? this.datas.get(id) : null;
	}
}
